package com.heima.common.exception;

import com.heima.common.dto.ResponseResult;
import com.heima.common.enums.AppHttpCodeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
@Slf4j
@RestControllerAdvice
public class BaseExceptionHandler {
    @ExceptionHandler(RuntimeException.class)
    public ResponseResult handlerRuntimeException(RuntimeException e){
        log.error("[全局运行异常]{}",e.getMessage());
        return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR,e.getMessage());
    }
    @ExceptionHandler(Exception.class)
    public ResponseResult handlerException(Exception e){
        log.error("[全局异常]{}",e.getMessage());
        return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR,e.getMessage());
    }
}
